"""
@author: Lin
@time: 2022/7/14 15:14
"""
from utils.array_utils import check_all


def merge(la, lb):
    ia = ib = 0
    lt = []
    while ia < len(la) and ib < len(lb):
        if la[ia] < lb[ib]:
            lt.append(la[ia])
            ia += 1
        else:
            lt.append(lb[ib])
            ib += 1
    lt += la[ia:]
    lt += lb[ib:]
    return lt


def merge_sort(arr):
    if len(arr) == 1:
        return arr
    mid_index = len(arr) // 2
    left_list = merge_sort(arr[:mid_index])
    right_list = merge_sort(arr[mid_index:])
    return merge(left_list, right_list)


if __name__ == '__main__':
    arra = [1, 3, 5, 7, 8, 9]
    arrb = [2, 4, 6]
    print(merge(arra, arrb))
    mylist = [6, 3, 8, 2, 4, 7, 9, 0]
    print(merge_sort(mylist))
    print(check_all(merge_sort, 1000))
